package robot;


import renderables.RenderablePoint;

public class Robot {
	
	  public Robot(int x, int y, double a, int r1, int r2) {
		    pos = new RenderablePoint(x, y);
		    angle = a;
		    rayRadius = r1;
		    sensorRadius = r2;
	}
	
	private RenderablePoint pos;
	private double angle;
	private int rayRadius;
	private int sensorRadius;
	
	public RayPoint[] rayPoints = new RayPoint[7];
	
	// Calculate if a point is inside the sensor area of the robot
	public boolean isPointInsideSensorArea(RenderablePoint point) {
		  
		  // check if point is inside the sensor area
		  
		  // we first check the distance between the robot and the point
		  double d = Math.sqrt((point.x-pos.x)*(point.x-pos.x)+(point.y-pos.y)*(point.y-pos.y));
		  
		  // this distance has to be between the two radius
		  if (d<rayRadius || d>sensorRadius) return false;
		  
		  // now we need to know if it's inside the semicercle of the heading robot
		  // first calculate the angle of the object respect the robot
		  double obsWorldAngle = Math.atan2(point.y-pos.y, point.x-pos.x);
		  double relativeAngle = angle - obsWorldAngle; 
		  
		  if (relativeAngle>-Math.PI/2 && relativeAngle<Math.PI/2) 
			  return true;
		  		
		  return false;
	}

	public RenderablePoint getCoordinates() {
		return pos;
	}

	public void setCoordinates(RenderablePoint pos) {
		this.pos = pos;
	}

	public double getAngle() {
		return angle;
	}

	public void setAngle(double angle) {
		this.angle = angle;
	}

	public int getRayRadius() {
		return rayRadius;
	}

	public void setRayRadius(int rayRadius) {
		this.rayRadius = rayRadius;
	}

	public int getSensorRadius() {
		return sensorRadius;
	}

	public void setSensorRadius(int sensorRadius) {
		this.sensorRadius = sensorRadius;
	}
	

	
}
